
/**
 * A dep is an observable that can have multiple
 * directives subscribing to it.
 */
var Dep = function Dep () {
	this.id = uid++;
	this.subs = [];
};

Dep.prototype.addSub = function addSub (sub) {
	this.subs.push(sub);
};

Dep.prototype.removeSub = function removeSub (sub) {
	remove(this.subs, sub);
};

Dep.prototype.depend = function depend () {
	if (Dep.target) {
		Dep.target.addDep(this);
	}
};

Dep.prototype.notify = function notify () {
	// stabilize the subscriber list first
	var subs = this.subs.slice();
	for (var i = 0, l = subs.length; i < l; i++) {
		subs[i].update();
	}
};


// the current target watcher being evaluated.
// this is globally unique because there could be only one
// watcher being evaluated at any time.
Dep.target = null;